package ControlLayer;


import java.util.ArrayList;

import DBLayer.DBProduct;
import DBLayer.IFDBProduct;
import ModelLayer.Product;
import ModelLayer.Supplier;
import ModelLayer.Tire;
import ModelLayer.Gearbox;
import ModelLayer.Glass;
import ModelLayer.Headlights;
import ModelLayer.BrakeDisc;

public class ProductCtr 
{
	public ProductCtr(){
		
		
	}
	
	//Method lists all products
	public ArrayList<Product> listAllProducts()
	{
		IFDBProduct dbPro = new DBProduct();
		ArrayList<Product> allPro = new ArrayList<Product>();
		allPro = dbPro.listAllProducts(false);
		return allPro;
	}
	
	//Method lists all tire objects in the DB
	public ArrayList<Tire> listAllTire()
	{
		IFDBProduct dbPro = new DBProduct();
		ArrayList<Tire> allPro = new ArrayList<Tire>();
		allPro = dbPro.listAllTires(false);
		return allPro;
	}
	
	//Method lists all gearbox objects in the DB
	public ArrayList<Gearbox> listAllGearbox()
	{
		IFDBProduct dbPro = new DBProduct();
		ArrayList<Gearbox> allPro = new ArrayList<Gearbox>();
		allPro = dbPro.listAllGearboxs(false);
		return allPro;
	}
	
	//Method lists all glass objects in the DB
	public ArrayList<Glass> listAllGlass()
	{
		IFDBProduct dbPro = new DBProduct();
		ArrayList<Glass> allPro = new ArrayList<Glass>();
		allPro = dbPro.listAllGlass(false);
		return allPro;
	}
	
	//Method lists all headlights objects in the DB
	public ArrayList<Headlights> listAllHeadlights()
	{
		IFDBProduct dbPro = new DBProduct();
		ArrayList<Headlights> allPro = new ArrayList<Headlights>();
		allPro = dbPro.listAllHeadlights(false);
		return allPro;
	}
	
	//Method lists all brakedisc objects in the DB
	public ArrayList<BrakeDisc> listAllBrakeDisc()
	{
		IFDBProduct dbPro = new DBProduct();
		ArrayList<BrakeDisc> allPro = new ArrayList<BrakeDisc>();
		allPro = dbPro.listAllBrakeDisc(false);
		return allPro;
	}
		
	//Method finds a product in the DB
	public Product findProduct(int productNumber, boolean retrieveAssociation)
	{
		IFDBProduct dbPro = new DBProduct();
		return dbPro.findProduct(productNumber, false);
	}
	
	//Method creates and inserts a tire object in the DB
	public void insertTire(int serialNumber, String productName,int supplierId, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, String fabricant, String description, String carModel, int modelYear, int minStock, int maxStock, String productType, String tireType, String tireSize)
	{
		DBProduct product = new DBProduct();
		Tire tireObj = new Tire();
		Supplier supObj = new Supplier(supplierId);
	
		tireObj.setSerialNumber(serialNumber);
		tireObj.setProductName(productName);
		tireObj.setSupplier(supObj);
		tireObj.setPurchasePrice(purchasePrice);
		tireObj.setSalesPrice(salesPrice);
		tireObj.setRentPrice(rentPrice);
		tireObj.setCountryOfOrigin(countryOfOrigin);
		tireObj.setFabricant(fabricant);
		tireObj.setDescription(description);
		tireObj.setCarModel(carModel);
		tireObj.setModelYear(modelYear);
		tireObj.setMinStock(minStock);
		tireObj.setMaxStock(maxStock);
		tireObj.setProductType(productType);
		tireObj.setTireType(tireType);
		tireObj.setTireSize(tireSize);
		try {product.insertProduct(tireObj);}
		catch(Exception e){
		}
	}
	
	//Method creates and inserts a gearbox object in the DB
	public void insertGearbox(int serialNumber, String productName,int supplierId, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, String fabricant, String description, String carModel, int modelYear, int minStock, int maxStock, String productType, String gearboxType, int gearAmount)
	{
		DBProduct product = new DBProduct();
		Gearbox gearObj = new Gearbox();
		Supplier supObj = new Supplier(supplierId);
	
		gearObj.setSerialNumber(serialNumber);
		gearObj.setProductName(productName);
		gearObj.setSupplier(supObj);
		gearObj.setPurchasePrice(purchasePrice);
		gearObj.setSalesPrice(salesPrice);
		gearObj.setRentPrice(rentPrice);
		gearObj.setCountryOfOrigin(countryOfOrigin);
		gearObj.setFabricant(fabricant);
		gearObj.setDescription(description);
		gearObj.setCarModel(carModel);
		gearObj.setModelYear(modelYear);
		gearObj.setMinStock(minStock);
		gearObj.setMaxStock(maxStock);
		gearObj.setProductType(productType);
		gearObj.setGearboxType(gearboxType);
		gearObj.setGearAmount(gearAmount);
		try {product.insertProduct(gearObj);}
		catch(Exception e){
		}
		
	}
	
	//Method creates and inserts a glass object in the DB
	public void insertGlass(int serialNumber, String productName,int supplierId, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, String fabricant, String description, String carModel, int modelYear, int minStock, int maxStock, String productType, String height, String width, String thickness)
	{
		DBProduct product = new DBProduct();
		Glass glassObj = new Glass();
		Supplier supObj = new Supplier(supplierId);
	
		glassObj.setSerialNumber(serialNumber);
		glassObj.setProductName(productName);
		glassObj.setSupplier(supObj);
		glassObj.setPurchasePrice(purchasePrice);
		glassObj.setSalesPrice(salesPrice);
		glassObj.setRentPrice(rentPrice);
		glassObj.setCountryOfOrigin(countryOfOrigin);
		glassObj.setFabricant(fabricant);
		glassObj.setDescription(description);
		glassObj.setCarModel(carModel);
		glassObj.setModelYear(modelYear);
		glassObj.setMinStock(minStock);
		glassObj.setMaxStock(maxStock);
		glassObj.setProductType(productType);
		glassObj.setHeight(height);
		glassObj.setWidth(width);
		glassObj.setThickness(thickness);
		try {product.insertProduct(glassObj);}
		catch(Exception e){
		}
	}
	
	//Method creates and inserts a headlight object in the DB
	public void insertHeadlights(int serialNumber, String productName,int supplierId, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, String fabricant, String description, String carModel, int modelYear, int minStock, int maxStock, String productType, String lightsType)
	{
		DBProduct product = new DBProduct();
		Headlights headObj = new Headlights();
		Supplier supObj = new Supplier(supplierId);
		
		headObj.setSerialNumber(serialNumber);
		headObj.setProductName(productName);
		headObj.setSupplier(supObj);
		headObj.setPurchasePrice(purchasePrice);
		headObj.setSalesPrice(salesPrice);
		headObj.setRentPrice(rentPrice);
		headObj.setCountryOfOrigin(countryOfOrigin);
		headObj.setFabricant(fabricant);
		headObj.setDescription(description);
		headObj.setCarModel(carModel);
		headObj.setModelYear(modelYear);
		headObj.setMinStock(minStock);
		headObj.setMaxStock(maxStock);
		headObj.setProductType(productType);
		headObj.setLightsType(lightsType);
		try {product.insertProduct(headObj);}
		catch(Exception e){
		}
	}
	
	//Method creates and inserts a brakedisc object in the DB
	public void insertBrakeDisc(int serialNumber, String productName,int supplierId, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, String fabricant, String description, String carModel, int modelYear, int minStock, int maxStock, String productType, String discType)
	{
	
		DBProduct product = new DBProduct();
		BrakeDisc brakeObj = new BrakeDisc();
		Supplier supObj = new Supplier(supplierId);
	
		brakeObj.setSerialNumber(serialNumber);
		brakeObj.setProductName(productName);
		brakeObj.setSupplier(supObj);
		brakeObj.setPurchasePrice(purchasePrice);
		brakeObj.setSalesPrice(salesPrice);
		brakeObj.setRentPrice(rentPrice);
		brakeObj.setCountryOfOrigin(countryOfOrigin);
		brakeObj.setFabricant(fabricant);
		brakeObj.setDescription(description);
		brakeObj.setCarModel(carModel);
		brakeObj.setModelYear(modelYear);
		brakeObj.setMinStock(minStock);
		brakeObj.setMaxStock(maxStock);
		brakeObj.setProductType(productType);
		brakeObj.setDiscType(discType);
		try {product.insertProduct(brakeObj);}
		catch(Exception e){
		}
	}
	
	//Method updates a tire object in the DB
	public int updateTire(int productNumber, int serialNumber, String productName,int supplierId, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, String fabricant, String description, String carModel, int modelYear, int minStock, int maxStock, String productType, String tireType, String tireSize)
	{
		IFDBProduct dbPro = new DBProduct();
		Tire tireObj = new Tire();
		Supplier supObj = new Supplier(supplierId);
		
		tireObj.setProductNumber(productNumber);
		tireObj.setSerialNumber(serialNumber);
		tireObj.setProductName(productName);
		tireObj.setSupplier(supObj);
		tireObj.setPurchasePrice(purchasePrice);
		tireObj.setSalesPrice(salesPrice);
		tireObj.setRentPrice(rentPrice);
		tireObj.setCountryOfOrigin(countryOfOrigin);
		tireObj.setFabricant(fabricant);
		tireObj.setDescription(description);
		tireObj.setCarModel(carModel);
		tireObj.setModelYear(modelYear);
		tireObj.setMinStock(minStock);
		tireObj.setMaxStock(maxStock);
		tireObj.setProductType(productType);
		tireObj.setTireType(tireType);
		tireObj.setTireSize(tireSize);
		return  dbPro.updateProduct(tireObj);
	}
	
	//Method updates a gearbox object in the DB
	public int updateGearbox(int productNumber, int serialNumber, String productName,int supplierId, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, String fabricant, String description, String carModel, int modelYear, int minStock, int maxStock, String productType, String gearboxType, int gearAmount)
	{
		IFDBProduct dbPro = new DBProduct();
		Gearbox gearObj = new Gearbox();
		Supplier supObj = new Supplier(supplierId);
		
		gearObj.setProductNumber(productNumber);
		gearObj.setSerialNumber(serialNumber);
		gearObj.setProductName(productName);
		gearObj.setSupplier(supObj);
		gearObj.setPurchasePrice(purchasePrice);
		gearObj.setSalesPrice(salesPrice);
		gearObj.setRentPrice(rentPrice);
		gearObj.setCountryOfOrigin(countryOfOrigin);
		gearObj.setFabricant(fabricant);
		gearObj.setDescription(description);
		gearObj.setCarModel(carModel);
		gearObj.setModelYear(modelYear);
		gearObj.setMinStock(minStock);
		gearObj.setMaxStock(maxStock);
		gearObj.setProductType(productType);
		gearObj.setGearboxType(gearboxType);
		gearObj.setGearAmount(gearAmount);
		return  dbPro.updateProduct(gearObj);
	}
	
	//Method updates a glass object in the DB
	public int updateGlass(int productNumber, int serialNumber, String productName,int supplierId, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, String fabricant, String description, String carModel, int modelYear, int minStock, int maxStock, String productType, String height, String width, String thickness)
	{
		IFDBProduct dbPro = new DBProduct();
		Glass glassObj = new Glass();
		Supplier supObj = new Supplier(supplierId);
		
		glassObj.setProductNumber(productNumber);
		glassObj.setSerialNumber(serialNumber);
		glassObj.setProductName(productName);
		glassObj.setSupplier(supObj);
		glassObj.setPurchasePrice(purchasePrice);
		glassObj.setSalesPrice(salesPrice);
		glassObj.setRentPrice(rentPrice);
		glassObj.setCountryOfOrigin(countryOfOrigin);
		glassObj.setFabricant(fabricant);
		glassObj.setDescription(description);
		glassObj.setCarModel(carModel);
		glassObj.setModelYear(modelYear);
		glassObj.setMinStock(minStock);
		glassObj.setMaxStock(maxStock);
		glassObj.setProductType(productType);
		glassObj.setHeight(height);
		glassObj.setWidth(width);
		glassObj.setThickness(thickness);
		return  dbPro.updateProduct(glassObj);
	}
	
	//Method updates a headlight object in the DB
	public int updateHeadlights(int productNumber, int serialNumber, String productName,int supplierId, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, String fabricant, String description, String carModel, int modelYear, int minStock, int maxStock, String productType, String lightsType)
	{
		IFDBProduct dbPro = new DBProduct();
		Headlights headObj = new Headlights();
		Supplier supObj = new Supplier(supplierId);
		
		headObj.setProductNumber(productNumber);
		headObj.setSerialNumber(serialNumber);
		headObj.setProductName(productName);
		headObj.setSupplier(supObj);
		headObj.setPurchasePrice(purchasePrice);
		headObj.setSalesPrice(salesPrice);
		headObj.setRentPrice(rentPrice);
		headObj.setCountryOfOrigin(countryOfOrigin);
		headObj.setFabricant(fabricant);
		headObj.setDescription(description);
		headObj.setCarModel(carModel);
		headObj.setModelYear(modelYear);
		headObj.setMinStock(minStock);
		headObj.setMaxStock(maxStock);
		headObj.setProductType(productType);
		headObj.setLightsType(lightsType);
		return  dbPro.updateProduct(headObj);
	}
	
	//Method updates a brakedisc object in the DB
	public int updateBrakeDisc(int productNumber, int serialNumber, String productName,int supplierId, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, String fabricant, String description, String carModel, int modelYear, int minStock, int maxStock, String productType, String discType)
	{
		IFDBProduct dbPro = new DBProduct();
		BrakeDisc brakeObj = new BrakeDisc();
		Supplier supObj = new Supplier(supplierId);
		
		brakeObj.setProductNumber(productNumber);
		brakeObj.setSerialNumber(serialNumber);
		brakeObj.setProductName(productName);
		brakeObj.setSupplier(supObj);
		brakeObj.setPurchasePrice(purchasePrice);
		brakeObj.setSalesPrice(salesPrice);
		brakeObj.setRentPrice(rentPrice);
		brakeObj.setCountryOfOrigin(countryOfOrigin);
		brakeObj.setFabricant(fabricant);
		brakeObj.setDescription(description);
		brakeObj.setCarModel(carModel);
		brakeObj.setModelYear(modelYear);
		brakeObj.setMinStock(minStock);
		brakeObj.setMaxStock(maxStock);
		brakeObj.setProductType(productType);
		brakeObj.setDiscType(discType);
		return  dbPro.updateProduct(brakeObj);
	}
	
	//Method deletes a product from the DB
	public void deleteProduct(int serialNumber)
	{
		DBProduct dbProduct = new DBProduct();
		dbProduct.deleteProduct(serialNumber);	
	}

}
